package com.ideal.frame.application.controller;

import com.ideal.frame.application.entity.Application;
import com.ideal.frame.application.entity.ApplicationSecret;
import com.ideal.frame.application.form.AppSearchForm;
import com.ideal.frame.application.form.AppSecretSearchForm;
import com.ideal.frame.application.service.ApplicationService;
import com.ideal.frame.common.dto.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author ybb
 * @Description
 * @Date 2021/8/24 16:53
 */
@RestController
@RequestMapping("/app")
@Api("应用管理")
public class ApplicationController {

    @Autowired
    ApplicationService applicationService;

    @PostMapping("/pages")
    public ResponseModel pages(@RequestBody AppSearchForm searchForm){
        return ResponseModel.success(applicationService.pages(searchForm));
    }

    @GetMapping("/getOne/{id}")
    public ResponseModel getById(@PathVariable long id){
        return ResponseModel.success(applicationService.getOne(id));
    }

    @PostMapping("/add")
    public ResponseModel add(@RequestBody Application application){
        applicationService.add(application);
        return ResponseModel.success();
    }

    @DeleteMapping("/del")
    public ResponseModel del(@RequestBody List<Long> ids){
        applicationService.del(ids);
        return ResponseModel.success();
    }

    @PostMapping("/update")
    public ResponseModel update(@RequestBody Application application){
        return null;
    }




    @PostMapping("/secretPages")
    public ResponseModel secretPages(@RequestBody AppSecretSearchForm searchForm){
        return ResponseModel.success(applicationService.secretPages(searchForm));
    }

    @PostMapping("/addSecret")
    @ApiOperation(value = "在应用下创建密钥")
    public ResponseModel addAppSecret(@RequestBody ApplicationSecret appUser){
        applicationService.addAppSecret(appUser);
        return ResponseModel.success();
    }

    @DeleteMapping("/delSecret")
    public ResponseModel delAppSecret(@RequestBody List<Long> ids){
        applicationService.delAppSecret(ids);
        return ResponseModel.success();
    }

    @GetMapping("/getOrgs")
    public ResponseModel getOrgs(){
        return ResponseModel.success(applicationService.getOrgs());
    }

    @GetMapping("/uniqueKey")
    public ResponseModel uniqueKey(){
        return ResponseModel.success(applicationService.uniqueKey());
    }

}
